package com.study.design.pattern.pattern.structural.proxy.dynamicproxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @Author: gongsl
 * @Date: 2025-03-19 21:36
 * @description: 支付功能代理类
 */
public class PaymentServiceInvocationHandler implements InvocationHandler {

    /**
     * 目标对象
     */
    private Object target;

    public PaymentServiceInvocationHandler(Object target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        // 在调用目标方法前做一些操作
        System.out.println("Logging: Payment is about to be processed.");
        // 执行目标方法
        Object result = method.invoke(target, args);
        // 在调用目标方法后做一些操作
        System.out.println("Logging: Payment has been processed.");
        return result;
    }
}
